﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace webapps.homefinance.Models
{
    public class HomeFinanceModel
    {
    }

    public class HomeFinanceException : Exception
    {
        public Exception Exception { set; get; }

        public HomeFinanceException(string message)
            : base(message)
        {

        }

        public HomeFinanceException(Exception e)
            :base(e.Message)
        {
            Exception = e;
        }
    }

    public enum HomeFinanceResposeType
    {
        Success,
        Information,
        Warning,
        Error
    }

    public class HomeFinanceResponseMessage
    {
        public HomeFinanceResposeType Type { set; get; }
        public String MessageText { set; get; }
        public HomeFinanceException Exception { set; get; }

        public HomeFinanceResponseMessage() { }

        public HomeFinanceResponseMessage(HomeFinanceException e)
        {
            Exception = e;
            MessageText = e.Message;
            Type = HomeFinanceResposeType.Error;
        }

        public HomeFinanceResponseMessage(string message, HomeFinanceResposeType type)
        {
            MessageText = message;
            Type = type;
        }

        public override String ToString()
        {
            return MessageText;
        }
    }

    public class HomeFinanceResponse
    {
        public bool IsSuccess { set; get; }
        public List<HomeFinanceResponseMessage> Messages { set; get; }

        public HomeFinanceResponse()
        {
            Messages = new List<HomeFinanceResponseMessage>();
        }

        public List<HomeFinanceResponseMessage> SetSuccess()
        {
            IsSuccess = true;

            return Messages;
        }

        public List<HomeFinanceResponseMessage> SetException(Exception e)
        {
            IsSuccess = false;
            Messages.Add(new HomeFinanceResponseMessage(new HomeFinanceException(e)));

            return Messages;
        }

        public List<HomeFinanceResponseMessage> AddMessage(HomeFinanceResponseMessage msg)
        {
            Messages.Add(msg);

            return Messages;
        }
    }

    public class HomeFinanceListResponse : HomeFinanceResponse
    {
        public object ItemList { set; get; }

        public void SetListData(object val)
        {
            ItemList = val;
        }
    }
}